package com.hot100.easy;

/**
 * @ClassName Demo11
 * @Description 环形链表//快慢指针,以快指针为准
 * @Author zt
 * @Date 15:28 2022/6/10
 * @Version 1.0
 **/
public class Demo11 {
    public static void main(String[] args) {


    }


    public boolean hasCycle(ListNode head) {

        ListNode fast=head;
        ListNode slow=head;

        if(head==null){
            return false;
        }

        while (fast!=null&&fast.next!=null){
            fast=fast.next.next;
            slow=slow.next;
            if(fast==slow){
                return true;
            }

        }
        return false;

    }

    class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }
}